<?php
namespace app\pay\controller;
use think\Input;
class Notifydemo extends Common{
    public function initialize(){
        parent::initialize(); 
    }  
    // 异步通知
    public function index(){ 
    	if(request()->isPost()){
            $order=db('channel_order')->where(array('orderid_out' =>input('orderid_out'),'state' =>2,'points' =>0))->find();
            if($order){  
                //创建签名
                $requestarray = array(
                    "orderid_out" =>$order['orderid_out'],
                    "money" => $order['money'], 
                    "number" => $order['number'],  
                    "version" => $this->sys['version'],   
                ); 
                ksort($requestarray); //按照键名进行升序排序 
                $Md5key=db('shop')->where('id',$order['shopid'])->value('appkey');
                $md5str = "";
                foreach ($requestarray as $key => $val) {
                    $md5str = $md5str . $key . "=" . $val . "&";
                } 
                $sign = strtoupper(md5($md5str . "key=" . $Md5key));  //签名转大写
                $insign=input('sign');
                if($sign===$insign){
                    if(db('channel_order')->where('orderid',$order['orderid'])->where('state',2)->update(['points'=>1])!=false){
                        $result = ['code'=>'SUCCESS','msg'=>'上分成功!'];
                    }else{
                        $result = ['code'=>-1,'msg'=>'上分失败，请重试!'];
                    }
                }else{
                    $result = ['code'=>-1,'msg'=>'签名错误!'];
                } 
            }else{
                $result = ['code'=>-1,'msg'=>'订单异常!'];
            } 
    	}else{
            $result = ['code'=>-1,'msg'=>'这样不好!'];
        }      
    	return json($result);
    }      
}  